﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;

namespace WEBSITE_BANDEAL.Admin
{
    public partial class hoaitest : System.Web.UI.Page
    {
        protected int ID
        {
            get { return 5; }

        }



        protected void Page_Load(object sender, EventArgs e)
        {


        }

        protected void AjaxFileUpload1_UploadComplete1(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
        {
            string filePath1 = MapPath(string.Format("~/admin/Images/{0}/", ID));
            if (!System.IO.Directory.Exists(filePath1))
                System.IO.Directory.CreateDirectory(filePath1);
            string filePath2 = MapPath(string.Format("~/admin/Images/{0}/thumbnail/", ID));
            if (!System.IO.Directory.Exists(filePath2))
                System.IO.Directory.CreateDirectory(filePath2);

            // LoaiSP_DAL han = new LoaiSP_DAL();

            // han.Insert(ID,e.FileName);
            string filePath = MapPath(string.Format("~/admin/Images/{0}/", ID)) + System.IO.Path.GetFileName(e.FileName);
            AjaxFileUpload1.SaveAs(filePath);
            System.Drawing.Image img = System.Drawing.Image.FromFile(string.Format("{0}admin/Images/{1}/{2}", Request.PhysicalApplicationPath, ID, System.IO.Path.GetFileName(e.FileName)));

            int height = Convert.ToInt32((299F * img.Height) / img.Width);
            System.Drawing.Image bmp1 = img.GetThumbnailImage(160, 160, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
            bmp1.Save(string.Format("{0}admin/Images/{1}/thumbnail/{2}", Request.PhysicalApplicationPath, ID, System.IO.Path.GetFileName(e.FileName)));


            // tao web moi di 4.0

        }
        public bool ThumbnailCallback()
        {
            return false;
        }
    }
}